{include file="header"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card-header">
                <div class="left">
                    <button class="layui-btn layui-btn-primary addline" onclick="xadmin.open('新建作品','{:url("cartoon/addzp")}',850,550)">新建作品</button>
                    <button class="layui-btn layui-btn-primary setstatus" onclick="setstatus()" style="display: none;">作品状态写入</button>
                    <button class="layui-btn layui-btn-primary selobj" onclick="sel()" data-type="sel">选择对象</button>
                    <button class="layui-btn layui-btn-danger del" onclick="del()">删除</button>

                </div>
                <div class="right">
                    <form action="{:url('cartoon/index')}" method="get" class="layui-form layui-col-space5 hide">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" class="layui-input" name="keyword" value="{:request()->get('keyword')}" placeholder="输入要找的作品名称">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" type="submit" lay-submit lay-filter="submit">搜索</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="layui-card-body">
                <table class="layui-table layui-form">
                    <thead>
                    <tr>
                        <th></th>
                        <th>作品名</th>
                        <th>原作者</th>
                        <th>动画制作公司</th>
                        <th>漫画连载状态</th>
                        <th>TV更新状态</th>
                        <th>漫画首更日期</th>
                        <th>TV首更日期</th>
                    </tr>
                    </thead>
                    <tbody>
                        {volist name="lists" id="item"}
                        <tr class="tr_{$item.id}{if $item.display eq 0} dls{/if}">
                            <td>
                                <a href="javascript:;" class="editbtn" onclick="xadmin.open('作品编辑','{:url("cartoon/editzp",["id"=>$item["id"]])}')">编辑</a>
                                <div style="display: none;" class="selone">
                                    <input type="checkbox" name="selone" lay-filter="selone" value="{$item.id}" lay-skin="primary" >
                                </div>
                            </td>
                            <td>
                                <a href="javascript:;" onclick="add({$item.id})">
                                    {$item.title} <br>
                                    {$item.title_jp}
                                </a>

                            </td>
                            <td>
                                {$item.author} <br>
                                {$item.author_jp}
                            </td>
                            <td>
                                {volist name="$item.companys" id="val"}
                                {$val.title_cn} <br>
                                {/volist}
                            </td>
                            <td>
                                {if $item.comics_status eq 1}
                                连载中(目前{$item.comics_end_words}话)
                                {else}
                                已完结{if $item.comics_all}(全{$item.comics_all}话){/if}
                                {/if} </td>
                            <td>
                                {if $item.cartoon_status eq 1}
                                更新中(目前{$item.tv_end_words}话)
                                {else}
                                已完结{if $item.cartoon_all}(全{$item.cartoon_all}话){/if}
                                {/if}
                            </td>
                            <td> {$item.comics_start_time} </td>
                            <td> {$item.tv_start_time} </td>
                        </tr>
                        {/volist}
                    </tbody>
                </table>

            </div>
            <div class="layui-card-body ">
                {$lists|raw}
            </div>
        </div>
    </div>
</div>
<div id="setstatus" style="display: none;">
    <form class="layui-form" style="margin-top: 35px;margin-left: 30px;">
        <div class="layui-form-item">
            <label class="layui-form-label">漫画状态</label>
            <div class="layui-inline">
                <input type="radio" name="comics_status" lay-filter="comics_status" value="1" title="连载中" checked>
                <input type="radio" name="comics_status" lay-filter="comics_status" value="2" title="已完结">

            </div>
            <div class="comics_all_box other_box" style="display: none;">
                <span>全</span><input type="text" name="comics_all" value="" autocomplete="off" class="other" placeholder=""><span>话</span>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">动画状态</label>
            <div class="layui-inline">
                <input type="radio" name="cartoon_status" lay-filter="cartoon_status" value="1" title="连载中" checked>
                <input type="radio" name="cartoon_status" lay-filter="cartoon_status" value="2" title="已完结">
            </div>
            <div class="cartoon_all_box other_box" style="display: none;">
                <span>全</span><input type="text" name="cartoon_all" value="" autocomplete="off" class="other" placeholder=""><span>话</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-inline">
                <button  class="layui-btn" lay-filter="setstatus" lay-submit="">
                    提交
                </button>
            </div>
        </div>
    </form>
</div>
<script>
    function del() {
        var id;
        let seltype = $('.selobj').data("type")
        if(seltype==="sel"){
            id = [$('[name="selone"]').last().val()]
        }else{
            id = getselall()
        }

        layer.confirm("{:lang('del.confirm')}",{icon: 3, title:'{:lang("tips")}'},function (index) {
            layer.close(index);
            request("POST",'{:url("cartoon/del")}',{
                id:id
            },function (res) {
                // for(let i in id){
                //     $(`.tr_${id[i]}`).remove()
                // }
                window.location.reload();
            })

        })
    }
    function add(id) {
        xadmin.open('作品详情','{:url("cartoon/details")}?id='+id,null,null,true,function () {
            window.location.reload();
        })
    }

    /**
     * @title 改变状态弹窗
     * @returns {boolean}
     */
    function setstatus() {
        var id = getselall()
        if(!id || id.length<1){
            layer.msg("请先选择对象")
            return false
        }
        layer.open({
            type: 1,
            title:'',
            content: $('#setstatus')
            ,area: ['500px', '300px']
            ,success:function () {
                form.on('radio(comics_status)', function(data){
                    if(data.value == 1){
                        $('.comics_all_box').hide()
                        $('[name="comics_all"]').val(0)
                    }else{
                        $('.comics_all_box').show()
                    }
                });
                form.on('radio(cartoon_status)', function(data){
                    if(data.value == 1){
                        $('.cartoon_all_box').hide()
                        $('[name="cartoon_all"]').val(0)
                    }else{
                        $('.cartoon_all_box').show()
                    }
                });
                //监听提交
                form.on('submit(setstatus)', function(data) {
                    data.field.ids=id
                    request("POST",'{:url("cartoon/setstatus")}',data.field,function (res,msg) {
                        window.location.reload();
                    })

                    return false;

                });
            }
        });
    }
</script>
{include file="footer"}